const mysql = require('mysql2/promise');
const Redis = require('redis');

// 创建MySQL连接池
const pool = mysql.createPool({
  host: process.env.DB_HOST,
  port: process.env.DB_PORT,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_DATABASE,
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0
});

// 创建Redis客户端
const redisClient = Redis.createClient({
  url: `redis://${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`
});
console.log(`redis://${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`)

// 连接Redis
redisClient.connect().catch(console.error);

// Redis错误处理
redisClient.on('error', (err) => console.error('Redis Client Error:', err));

module.exports = {
  pool,
  redisClient
};